package zuoye05;

import java.util.*;

public class doudizhu {
       public static void main(String[] args) {
           /*
           * 斗地主
           * 54张牌，三个玩家玩，交替摸牌，每人17张，最后三张留作底牌。*/
       ArrayList<String> treemap = new ArrayList<String>();
       String[] colors={"♠","♣","♦","♥"};
       String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
       treemap.add("大王");
       treemap.add("小王");
       for(String number:numbers){
              for(String color:colors){
               treemap.add(color+number);
              }
       }
       System.out.println(treemap);
              TreeMap<Integer,String> treeMap= new TreeMap<Integer,String>();
              for(int i=0;i<54;i++){
                     treeMap.put(i+1,treemap.get(i));
              }
              ArrayList<Integer> bbb=new ArrayList<>();
              for(int i=0;i<54;i++){
                     bbb.add(i+1);
              }
              Collections.shuffle(bbb);
              System.out.println(treeMap);
       //洗牌
             // Collections.shuffle(poker);
              //System.out.println(poker);
              Player p1=new Player();p1.setName("老王");
              Player p2=new Player();p2.setName("老李");
              Player p3=new Player();p3.setName("老六");
              ArrayList<String> dipai = new ArrayList<>();
              TreeMap<Integer,String> aaa=new TreeMap<>();
              //摸牌
              for(int i=0;i<treeMap.size();i++){
                     //获取每一张的牌
                     Integer key=bbb.get(i);
                     String  p=treeMap.get(i);
                     if(i>=51)
                     {
                            dipai.add(treeMap.get(key));
                     }
                     else if(i%3==0)
                     {
                            p1.getTreeMap().put(key,treeMap.get(key));
                     }
                     else if(i%3==1) {
                            p2.getTreeMap().put(key, treeMap.get(key));
                     }
                     else if (i%3==2) {

                            p3.getTreeMap().put(key,treeMap.get(key));
                     }
              }

              System.out.println(p1.getName()+"的牌是"+p1.getTreeMap());
              System.out.println(p2.getName()+"的牌是"+p2.getTreeMap());
              System.out.println(p3.getName()+"的牌是"+p3.getTreeMap());
              System.out.println("底牌:"+dipai);

       }

}
